<!-- templates/base.html -->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>农产品溯源平台</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>

    <style>
        body {
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        .navbar-custom {
            padding: 1rem 0; /* 扩展导航栏高度 */
        }

        .navbar-brand {
            font-weight: bold;
             font-size: 1.5rem;
        }

        .content {
            flex: 1;
            padding: 2rem 0;
        }

        .footer {
            padding: 1rem 0;
            background-color: #f8f9fa;
        }

    </style>
</head>
<body>

<!-- 导航栏 -->
<nav class="navbar navbar-expand-lg navbar-light bg-light navbar-custom">
    <div class="container">
        <a class="navbar-brand text-primary" href="{% url 'home' %}">农产品溯源平台</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
                aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav ms-auto">
                {% if user.is_authenticated %}
                <li class="nav-item">
    <span class="nav-link text-muted" style="cursor: default;">
        用户名：{{ user.username }} ({{ user.get_role_display }})
    </span>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="{% url 'dashboard' %}">
                        {% if user.is_admin %}
                        管理面板
                        {% else %}
                        用户面板
                        {% endif %}
                    </a>
                </li>

                <li class="nav-item">
                    <a class="nav-link" href="{% url 'logout' %}">退出登录</a>
                </li>
                {% else %}
                <li class="nav-item">
                    <a class="nav-link" href="{% url 'login' %}">登录</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="{% url 'register' %}">注册</a>
                </li>
                {% endif %}
            </ul>
        </div>
    </div>
</nav>

<!-- 主要内容 -->
<main class="content container">
    <!-- 消息提示区域 -->
    {% if messages %}
    <div class="container mt-4">
        {% for message in messages %}
        {% if forloop.first %}
        <div class="alert alert-{{ message.tags|default:'info' }} alert-dismissible fade show" role="alert">
            <strong>提示：</strong> {{ message }}
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
        {% endif %}
        {% endfor %}
    </div>
    {% endif %}

    <!-- 子页面内容 -->
    {% block content %}{% endblock %}
</main>

<!-- 页脚 -->
<footer class="footer">
    <div class="container text-center">
        <p class="text-muted mb-0">© 2025 农产品溯源加密平台</p>
    </div>
</footer>

</body>
</html>
